home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / hexify.arc / hexify.c < prev    next >
C/C++ Source or Header  |  1989-03-31  |  1KB  |  49 lines

  1. /*
  2.  *  Binary-to-hex utility -- conquer BITNET mailers!!
  3.  *
  4.  *  Rewrite binary file as a text file containing hexadecimal
  5.  *  digits
  6.  *
  7.  *  Michal Jaegermann, 19 March 1989
  8.  */
  9.  
  10. #include <stdio.h>
  11. /* LWIDTH bytes --- will put twice as many characters on output line */
  12. #define LWIDTH 32
  13.  
  14. main(argc, argv)
  15. int argc;
  16. char **argv;
  17. {
  18.     int ch, count = 0;
  19.     FILE *fin, *fout;
  20.     
  21.     if (argc != 3) {
  22.         fprintf(stderr, "usage: %s <infile> <outfile>\n", argv[0]);
  23.         exit(1);
  24.     }
  25.     
  26.     if (NULL == (fin = fopen(argv[1],"rb"))){
  27.         fprintf(stderr, "cannot find input file %s", argv[1]);
  28.     }
  29.     if (NULL == (fout = fopen(argv[2],"w"))){
  30.         fprintf(stderr, "cannot open output file %s", argv[2]);
  31.     }
  32.     
  33.     fprintf(fout, "BEGIN %s\n", argv[1]);
  34.     while (EOF != (ch = getc(fin))) {
  35.         fprintf(fout, "%02x", (unsigned) ch);
  36.         if (LWIDTH == (++count)) {
  37.             count = 0;
  38.             fprintf(fout,"\n");
  39.         }
  40.     }
  41.     fprintf(fout, "\nEND\n");
  42.     /*
  43.      * we do not care if we have an extra new line - restore
  44.      * utility will gobble it in any case
  45.      */
  46.     exit(0);
  47. }
  48.  
  49.